#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        if(nums.empty()) return 0;
        vector<int> result;
        for(int i = 0; i < nums.size(); ++i) {
            if(result.empty() || nums[i] > result.back()) {
                result.push_back(nums[i]);
            }
        }
        // 把去重后的元素写回原数组
        for(int i = 0; i < result.size(); ++i) {
            nums[i] = result[i];
        }
        return result.size();
    }
};

int main() {
    Solution sol;
    vector<int> nums = {0,0,1,1,1,2,2,3,3,4};
    int len = sol.removeDuplicates(nums);
    cout << "去重后长度: " << len << endl;
    cout << "去重后的数组: ";
    for(int i = 0; i < len; ++i) {
        cout << nums[i] << " ";
    }
    cout << endl;
    return 0;
}